﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using VCN.App.DataTransferObjects;

namespace VCN.App.DataAccessLayer
{
    public class ContactUsDAO
    {
        public static void excute(string store, string[] _bien, string[] _giatri)
        {
            System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
            string driver = (string)settingsReader.GetValue("ConnectionString", typeof(string));
            SqlConnection m_conn = new SqlConnection(driver);
            m_conn.Open();
            SqlCommand sqlcom = new SqlCommand(store, m_conn);
            sqlcom.CommandType = CommandType.StoredProcedure;
            for (int i = 0; i < _bien.Length; i++)
            {
                sqlcom.Parameters.AddWithValue(_bien[i], _giatri[i]);
            }
            try
            {
                sqlcom.ExecuteNonQuery();
                m_conn.Close();
            }
            catch (Exception exp)
            {
                m_conn.Close();
                HttpContext.Current.Response.Write(exp.ToString());
            }
        }
        public static void insert(ContactUsObject obj_Contact)
        {
            string[] parameter = new string[5] { "@Name", "@Email", "@Subject", "@CreatedDate", "@Message" };
            string[] values = new string[5] {obj_Contact.Name,obj_Contact.Email,obj_Contact.Subject,obj_Contact.Datetime.ToString(),obj_Contact.Message };
            excute("sp_tblContactUs_Insert", parameter, values);
        }
    }
}
